package com.litq.education.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.litq.education.bean.UserTable;

import com.litq.education.mapper.UserMapper;
import com.litq.education.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Map;

/**
 * UserServiceImpl 实现类
 *
 * @author litq
 * @version v1.0
 * @since 2019/2/10 1:31
 */
//@Service
@Service("UserService")
public class UserServiceImpl implements UserService {
    private static final Logger logger = LoggerFactory.getLogger(UserServiceImpl.class);
    @Resource
    private UserMapper userMapper;


    /**
     * @param name     姓名
     * @param password 密码
     * @return 返回user 成功 ，返回null 密码错误
     * @Date 2019-8-14
     * @author Litq
     * @version 1.0
     */
    @Override
    public UserTable doLogin(String name, String password) {
        logger.info("----------------------------------开始进行登录逻辑处理");
        QueryWrapper<UserTable> ew = new QueryWrapper<UserTable>();
        ew.eq("user_name", name);
        ew.eq("pass_word", password);
        UserTable ut = userMapper.selectOne(ew);
        logger.info("----------------------------------查询结果打印" + ut);
        return ut;
    }

    /**
     * @param name 姓名
     * @return 返回user 成功 ，返回1 用户不存在
     * @Date 2019-8-14
     * @author Litq
     * @version 1.0
     */
    @Override
    public UserTable loginQuery(String name) {
        logger.info("----------------------------------开始进行查询逻辑处理");
        QueryWrapper<UserTable> ew = new QueryWrapper<UserTable>();
        ew.eq("user_name", name);
        UserTable ut = userMapper.selectOne(ew);
        logger.info("----------------------------------查询结果打印" + ut);
        return ut;
    }


    /**
     * fetch data by rule id
     *
     * @return 返回0 成功 ，返回1 失败
     * @author Litq
     * @version 1.0
     */
    @Override
    public int res(Map<String, Object> map) {
        logger.info("----------------------------------开始进行查询逻辑处理");
        String name = map.get("name").toString();
        String password = map.get("password").toString();
        String phone = map.get("phone").toString();
        String sex = map.get("sex").toString();
        String creatTime = map.get("creatTime").toString();
        logger.info("----------------------------------开始打印获得的数据");
        logger.info("----------------------------------name：" + name);
        logger.info("----------------------------------password：" + password);
        logger.info("----------------------------------phone：" + phone);
        logger.info("----------------------------------sex：" + sex);
        logger.info("----------------------------------creatTime：" + creatTime);

        UserTable user = new UserTable();
        user.setUserName(name);
        user.setPassWord(password);
        user.setCreateDate(creatTime);
        user.setSex(sex);
        user.setPhoneNum(phone);
        int sign = userMapper.insert(user);

        return sign;
    }
}
